var add,edit,setVal,vrsnType;
require(['select2', 'date','validator','jquery-form'], function() {
    var $formData = $('#formData');
    $formData.initForm();

    add = function(fn) {
        addOrUpdate("/upgPhone/editUpgPhoneVrsn.htm",fn);
    };
    
    edit = function(fn) {
        addOrUpdate("/upgPhone/editUpgPhoneVrsn.htm",fn);
    };

    reset = function (type){
        $formData.reset($formData);
        if(isIE()) {   
            $('#upgFile').replaceWith($('#upgFile').clone(true));
        }else{
	        $("#upgFile").val('');
	    }
        $("#vrsnType").val(type);
    };

    
    setVal = function (id){
		$.ajaxExt({
			url :"/upgPhone/getUpgPhoneVrsn.htm",
			data : {'vrsnId' : id}
		}).done(function(data){
			reset();
			$formData.setValues(data);
		});
	};

    function addOrUpdate(url,callBack){
        var result = $.validator($formData);
        if (result) {
        	$formData.ajaxSubmit({
				dataType : 'JSON',
				success : function(result){
					callBack();
				},
				error : function() {
					$.messager.alert("错误", "系统异常", "error");
				}
			});
        }
    }
    
    function isIE() {
        if (!!window.ActiveXObject || "ActiveXObject" in window)
          return true;
        else
          return false;
      }

});